package 设计模式.创建型.单例模式.几种单例的实现;

import java.util.concurrent.atomic.AtomicLong;

public class IdGeneratorDubboCheck {
    private AtomicLong id = new AtomicLong(0);
    private static IdGeneratorDubboCheck instance;
    private IdGeneratorDubboCheck() {}
    public static IdGeneratorDubboCheck getInstance() {
        if (instance == null) {
            synchronized(IdGeneratorDubboCheck.class) {
                // 此处为类级别的锁
                if (instance == null) {
                    instance = new IdGeneratorDubboCheck();
                }
            }
        }
        return instance;
    }
    public long getId() {
        return id.incrementAndGet();
    }
}
